<template>
    <!-- 对话框表单 -->
    <div>

            
        <!-- 表格顶部菜单 -->
        <!-- 自定义按钮请使用插槽，甚至公共搜索也可以使用具名插槽渲染，参见文档 -->
        <TableHeader :buttons="['add', 'columnDisplay', 'quickSearch']" :quick-search-placeholder="t('搜索')"></TableHeader>
        <!-- 表格 -->
        <!-- 表格列有多种自定义渲染方式，比如自定义组件、具名插槽等，参见文档 -->
        <!-- 要使用 el-table 组件原有的属性，直接加在 Table 标签上即可 -->
        
        <Table ref="tableRef" :pagination="false">
            
            <template #status>
                <!-- 在插槽内，您可以随意发挥，通常使用 el-table-column 组件 -->
                <el-table-column :label="t('操作')" align="center" width="150" class-name="business-name" height="200">
                    <template #default="scope">
                        <div v-if="scope.row.user_id > 0">
                            <div>
                                <div class="btn ml-0 mt-0" @click="add(scope)">{{ t('添加') }}</div>
                            </div>
                            
                            <div :class="[scope.row.status.includes('1') ? 'btn btn-info ml-0 mt-5' : 'btn ml-0 mt-5']" @click="setStatus(scope.row.id, 1, scope.row)">{{ t('成交') }}</div>
                            <div :class="[scope.row.status.includes('0') ? 'btn btn-info mt-5 ml-5' : 'btn mt-5 ml-5']" @click="setStatus(scope.row.id, 0, scope.row)">{{ t('终止') }}</div>
                            <div class="btn ml-0 mt-5" @click="edit(scope)">{{ t('编辑') }}</div>
                            <el-popconfirm :title="t('确定要删除这条数据吗') + '?'" @confirm="del(scope)">
                                <template #reference>
                                    <div class="btn ml-5 mt-5">{{ t('删除') }}</div>
                                </template>
                            </el-popconfirm>
                        </div>
                        <div v-if="scope.row.user_id == 0">
                            <div class="btn ml-0 mt-0" @click="add(scope)">{{ t('添加') }}</div>
                            <div v-if="scope.row.user_id == 0" :class="[scope.row.status.includes('1') ? 'btn btn-info mt-0 ml-5' : 'btn mt-0 ml-5']" @click="setStatus(scope.row.id, 1, scope.row)">{{ t('完成') }}</div>
                            <div class="btn ml-0 mt-5" @click="edit(scope)">{{ t('编辑') }}</div>
                            <el-popconfirm :title="t('确定要删除这条数据吗')" @confirm="del(scope)">
                                <template #reference>
                                    <div class="btn ml-5 mt-5">{{ t('删除') }}</div>
                                </template>
                            </el-popconfirm>
                        </div>
                    </template>
                </el-table-column>
            </template>
        </Table>

        <PopupForm :order_id="state.order_id" />


    </div>
</template>

<script setup lang="ts">
import { ref, provide, onMounted, reactive, markRaw } from 'vue'
import baTableClass from '/@/utils/baTable'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { number_format } from '/@/utils/common'
import { useI18n } from 'vue-i18n'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import router from '/@/router/index'
import { useRoute } from 'vue-router'
import { saveOrderImagesApi, getAgentApi, delAgentApi, updateOtherCostApi, updateSaleRateApi, updateMarketProfitApi, updateProfitApi, updateLogisticsAmountApi, updateAddedApi, updateTariffApi, updateDrawbackAmountApi, updateDrawbackRateApi, updateCostApi, updateAmountUsdApi, changeStatusApi, detailApi, changeOrderTypeApi, updateAmountApi, updateTermApi, changeTradeTypeApi, updateTelApi, updateAddressApi, updateNoteApi } from '/@/api/most/customer/order'

import FormItem from '/@/components/formItem/index.vue'

import PopupForm from './popupForm.vue'

defineOptions({
    name: 'customer_order/index',
})


const props = defineProps(['order_id'])
const emit = defineEmits(["hideCheckBill"])



const close = (done: () => void) => {
    emit("hideCheckBill")
    done()
}

const { t } = useI18n()
const tableRef = ref()

const route = useRoute()

const state = reactive({
    order_id: props.order_id,
    
});


let optButtons = defaultOptButtons([])
// 自定义一个新的按钮
let newButton: OptButton[] = [
    {
        render: 'basicButton', // 渲染方式:tipButton=带tip的按钮,confirmButton=带确认框的按钮,moveButton=移动按钮
        name: 'edit',
        title: 'edit',
        text: t('编辑'),
        type: 'primary',
        class: 'btn btn-primary btn-small btn-sm ml-0 mt-5',
        icon: '',
    },{
        render: 'confirmButton',
        name: 'delete',
        title: '',
        text: t('删除'),
        type: 'danger',
        class: 'btn btn-danger ml--6 mt-5 btn-small',
        icon: '',
        popconfirm: {
            confirmButtonText: t('删除'),
            cancelButtonText: t('取消'),
            confirmButtonType: 'danger',
            title: t('确定要删除这条数据吗') + '?',
        }
    }
]

// 创建一个新的 Date 对象来获取当前日期
const currentDate = new Date();

// 获取年、月和日
const year = currentDate.getFullYear();
const month = String(currentDate.getMonth() + 1).padStart(2, '0'); // 月份是从 0 开始计数，所以要加 1
const day = String(currentDate.getDate()).padStart(2, '0');

// 组合成 YYYY-MM-DD 格式的日期字符串
const formattedDate = `${year}-${month}-${day}`;

// 新按钮合入到默认的按钮数组
optButtons = newButton.concat(optButtons)
/**
 * baTable 内包含了表格的所有数据且数据具备响应性，然后通过 provide 注入给了后代组件
 */
const baTable = new baTableClass(
    new baTableApi('/system/customer.OrderBill/'),
    {
        pk: 'id',
        column: [
            { label: t('No.'), prop: 'id', align: 'center', width: 70, type: 'index' },
            { label: t('付款金额'), prop: 'amount', align: 'center', width: 150 },
            { label: t('付款日期'), prop: 'create_time', align: 'center' },
            { label: t('备注'), prop: 'notes', align: 'center' },
            { label: t('操作'), align: 'center', render: 'buttons', buttons: optButtons, width: 160 },
        ],
        dblClickNotEditColumn: ['all'],
        defaultOrder: { prop: 'id', order: 'desc' },
    },
    {
        defaultItems: { order_id: state.order_id, create_time: formattedDate, type: 'payment', 'currency': 'CNY' },
    },{
        
    },{
        getIndex: ({ res }: { res: ApiResponse }) => { // 查看后
        },
        postDel: ({ res }:{ res: ApiResponse }) => { // 删除后
            
        },
    }
)

provide('baTable', baTable)




onMounted(() => {
    baTable.table.ref = tableRef.value


    baTable.table.filter!.order_id = state.order_id;
    
    baTable.table.filter!.type = 'payment';
    baTable.getIndex()?.then(() => {
        baTable.initSort()
        baTable.dragSort()
    })
})
</script>

<style scoped lang="scss">

:deep(.el-image){
    // width: 60px;
    // height: 60px;
    width: unset;
    height: unset;
    // max-height: 100px;
    // max-width: 80px;
    // max-height: 80px;
}
:deep(td.business-name > div.cell) {
    min-height: 80px;
    display:flex;
    justify-content:center; 
    align-items:center;
}
.tian{
    cursor: pointer;
}
.tian:hover{
    color: #409EFF;
}

:deep(.el-image > img){
    
}
:deep(.ba-data-table .btn){
    padding: 4px 14px;
}


:deep(.ba-data-table .margin-left-none:last-child){
    margin-bottom: 0px;
}
:deep(.table-operate-text){
    padding-left: 0;
}
:deep(.font-size-13){
    font-size: 13px;
}
:deep(.pay-type .el-radio){
    margin-right: 10px;
}
pre{
    font-family: 'Helvetica Neue',Helvetica,'PingFang SC','Hiragino Sans GB','Microsoft YaHei','微软雅黑',Arial,sans-serif;
}
:deep(.ba-operate-dialog .el-dialog__body){
    padding-bottom: 0;
    padding-left: 0;
    padding-right: 0;
}
:deep(.quotation-scrollbar .el-scrollbar:first-child > .el-scrollbar__wrap){
    height: 100%;
}
:deep(.ml-0){
    margin-left: 0!important;
}
:deep(.mt-8){
    margin-top: 8px;
}
:deep(.ml--6){
    margin-left: -6px;
}
:deep(.ml-5){
    margin-left: 5px;
}
:deep(.mt-5){
    margin-top: 5px;
}

:deep(.el-table__row:hover td){
    background: unset!important;;
}

    // border-color: rgb(234, 234, 234);

:deep(.el-table th.el-table__cell){
    background: rgb(245, 245, 246);
    color: #000;
    border-color: rgb(234, 234, 234);
}



.product-info :deep(.el-input__wrapper:hover){
    box-shadow: 0 0 0 1px #c0c4cc inset;
}
.product-info :deep(.el-input__wrapper.is-focus){
    box-shadow: 0 0 0 1px #409eff inset;
}
.product-info :deep(.el-form-item__label){
    padding-right: 0;
}

:deep(.el-upload--picture-card){
    height: 50px;
    width: 50px;
}
:deep(.el-upload-list--picture-card .el-upload-list__item){
    width: 50px;
    height: 50px;
}



.del-image{
    position: absolute; 
    top: 0px; 
    z-index: 9; 
    cursor: pointer;
    border: 1px solid #409eff;
    background: #409eff;
    color: #fff;
    width: 50px;
    text-align: center;
    font-size: 12px;
    height: 22px;
    line-height: 22px;
}

.del-image:hover{
    background: #0354a4;
}

:deep(.ml-6){
    margin-left: 12px;
}

 

</style>
